package com.kefu.exam.handler;

import com.kefu.common.context.KefuContext;
import com.kefu.common.util.JacksonUtil;
import com.kefu.exam.enums.TipType;
import com.kefu.exam.mapper.ExamSubjectAnswerMapper;
import com.kefu.exam.mapper.ExamSubjectMapper;
import com.kefu.exam.model.ExamSubject;
import com.kefu.exam.model.ExamSubjectAnswer;
import com.kefu.exam.service.ExamSubjectService;
import com.kefu.exam.vo.ExamSubjectInsertVo;
import com.kefu.exam.vo.SubjectUnit;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * ClassName: Comprehensive
 * Package: com.kefu.exam.handler
 * Date: 2022/9/22 16:02
 * Author: xiaoyu
 * Description:多选题的处理逻辑
 */
@Slf4j
public class Comprehensive implements SubjectTipHandler{
    @Override
    public void subjectInitHandle(ExamSubject subject, ExamSubjectAnswerMapper subjectAnswerMapper, ExamSubjectMapper examSubjectMapper, KefuContext context) {

    }

    @Override
    public SubjectUnit expressTextSubject(ExamSubjectInsertVo vo, String subjectTypeId, KefuContext context, ExamSubjectService subjectService, ExamSubjectAnswerMapper subjectAnswerMapper, ExamSubjectMapper subjectMapper) {
        SubjectUnit unit = null;
        {
            ExamSubject info = vo.convert();
            unit = subjectService.initSubjectUnit(info, TipType.CheckBox, subjectTypeId, context);
        }
        {
            // A.文字
            // B 图形
            // C.符号
            // D一切说明物
            if (vo.getExamSubjectAnswerList() != null && vo.getExamSubjectAnswerList().size() > 0) {
                List<ExamSubjectAnswer> examSubjectAnswerList =
                        vo.getExamSubjectAnswerList();
                for (int i = 0; i < examSubjectAnswerList.size(); i++) {
                    ExamSubjectAnswer answer = examSubjectAnswerList.get(i);
                    answer.setSubjectId(unit.getSubject().getSubjectId());
                    answer.setAnswerStatus(1);
                    answer.setAnswerSort(i);
                    int i1 = subjectAnswerMapper.insert(answer);
                    log.info("添加综合题[{}]:{}", i1, JacksonUtil.toString(answer));
                }
            }
        }
        // --------------------------------------------------------------------
        unit = subjectService.getSubjectUnit(unit.getSubject().getSubjectId());
        return unit;
    }

    @Override
    public int runPointWeight(SubjectUnit unit) {
        return 0;
    }
}
